package cn.iocoder.yudao.module.handguard.controller.app.wealthrecord;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;

import cn.iocoder.yudao.module.handguard.controller.app.wealthrecord.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.wealthrecord.WealthRecordDO;
import cn.iocoder.yudao.module.handguard.convert.wealthrecord.WealthRecordConvert;
import cn.iocoder.yudao.module.handguard.service.wealthrecord.WealthRecordService;

@Tag(name = "小程序 - 用户-财富值明细记录")
@RestController
@RequestMapping("/hutai/wealth-record")
@Validated
public class WealthRecordController {

    @Resource
    private WealthRecordService wealthRecordService;

//    @PostMapping("/create")
//    @Operation(summary = "创建用户-财富值明细记录")
//    public CommonResult<Long> createWealthRecord(@Valid @RequestBody WealthRecordCreateReqVO createReqVO) {
//        return success(wealthRecordService.createWealthRecord(createReqVO));
//    }

//    @PutMapping("/update")
//    @Operation(summary = "更新用户-财富值明细记录")
//    @PreAuthorize("@ss.hasPermission('hutai:wealth-record:update')")
//    public CommonResult<Boolean> updateWealthRecord(@Valid @RequestBody WealthRecordUpdateReqVO updateReqVO) {
//        wealthRecordService.updateWealthRecord(updateReqVO);
//        return success(true);
//    }

//    @DeleteMapping("/delete")
//    @Operation(summary = "删除用户-财富值明细记录")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('hutai:wealth-record:delete')")
//    public CommonResult<Boolean> deleteWealthRecord(@RequestParam("id") Long id) {
//        wealthRecordService.deleteWealthRecord(id);
//        return success(true);
//    }

//    @GetMapping("/get")
//    @Operation(summary = "获得用户-财富值明细记录")
//    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('hutai:wealth-record:query')")
//    public CommonResult<WealthRecordRespVO> getWealthRecord(@RequestParam("id") Long id) {
//        WealthRecordDO wealthRecord = wealthRecordService.getWealthRecord(id);
//        return success(WealthRecordConvert.INSTANCE.convert(wealthRecord));
//    }

    @GetMapping("/list")
    @Operation(summary = "获得用户-财富值明细记录列表")
    public CommonResult<List<WealthRecordRespVO>> getWealthRecordList() {
        //当前用户id
        Long userId = getLoginUser().getId();
        List<WealthRecordDO> list = wealthRecordService.getWealthRecordList(userId);
        return success(WealthRecordConvert.INSTANCE.convertList(list));
    }

//    @GetMapping("/page")
//    @Operation(summary = "获得用户-财富值明细记录分页")
//    @PreAuthorize("@ss.hasPermission('hutai:wealth-record:query')")
//    public CommonResult<PageResult<WealthRecordRespVO>> getWealthRecordPage(@Valid WealthRecordPageReqVO pageVO) {
//        PageResult<WealthRecordDO> pageResult = wealthRecordService.getWealthRecordPage(pageVO);
//        return success(WealthRecordConvert.INSTANCE.convertPage(pageResult));
//    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出用户-财富值明细记录 Excel")
//    @PreAuthorize("@ss.hasPermission('hutai:wealth-record:export')")
//    @OperateLog(type = EXPORT)
//    public void exportWealthRecordExcel(@Valid WealthRecordExportReqVO exportReqVO,
//              HttpServletResponse response) throws IOException {
//        List<WealthRecordDO> list = wealthRecordService.getWealthRecordList(exportReqVO);
//        // 导出 Excel
//        List<WealthRecordExcelVO> datas = WealthRecordConvert.INSTANCE.convertList02(list);
//        ExcelUtils.write(response, "用户-财富值明细记录.xls", "数据", WealthRecordExcelVO.class, datas);
//    }

}
